package com.ruoyi.web.controller.swimming;

import java.util.List;

import com.ruoyi.swimming.domian.SwimmingTicket;
import com.ruoyi.swimming.service.ISwimmingTicketService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 泳票Controller
 * 
 * @author ruoyi
 * @date 2021-07-17
 */
@RestController
@RequestMapping("/system/ticket")
public class SwimmingTicketController extends BaseController
{
    @Autowired
    private ISwimmingTicketService swimmingTicketService;

    /**
     * 查询泳票列表
     */
    @PreAuthorize("@ss.hasPermi('system:ticket:list')")
    @GetMapping("/list")
    public TableDataInfo list(SwimmingTicket swimmingTicket)
    {
        startPage();
        List<SwimmingTicket> list = swimmingTicketService.selectSwimmingTicketList(swimmingTicket);
        return getDataTable(list);
    }

    /**
     * 导出泳票列表
     */
    @PreAuthorize("@ss.hasPermi('system:ticket:export')")
    @Log(title = "泳票", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SwimmingTicket swimmingTicket)
    {
        List<SwimmingTicket> list = swimmingTicketService.selectSwimmingTicketList(swimmingTicket);
        ExcelUtil<SwimmingTicket> util = new ExcelUtil<SwimmingTicket>(SwimmingTicket.class);
        return util.exportExcel(list, "泳票数据");
    }

    /**
     * 获取泳票详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:ticket:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(swimmingTicketService.selectSwimmingTicketById(id));
    }

    /**
     * 新增泳票
     */
    @PreAuthorize("@ss.hasPermi('system:ticket:add')")
    @Log(title = "泳票", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SwimmingTicket swimmingTicket)
    {
        return toAjax(swimmingTicketService.insertSwimmingTicket(swimmingTicket));
    }

    /**
     * 修改泳票
     */
    @PreAuthorize("@ss.hasPermi('system:ticket:edit')")
    @Log(title = "泳票", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SwimmingTicket swimmingTicket)
    {
        return toAjax(swimmingTicketService.updateSwimmingTicket(swimmingTicket));
    }

    /**
     * 删除泳票
     */
    @PreAuthorize("@ss.hasPermi('system:ticket:remove')")
    @Log(title = "泳票", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(swimmingTicketService.deleteSwimmingTicketByIds(ids));
    }
}
